import requests

from config.setting import Configure


class requestHandler():
    # 每次都实例化都是一个新窗口
    def __init__(self):
        self.session = requests.Session()

    def send(self,method,url,params=None,data=None,json=None,**kwags):
        res = self.session.request(method,url,params=params,data=data,json=json,**kwags)
        try:
            return res.json()
        except ValueError:
            print(res)
    #关闭
    def close(self):
        self.session.close()

if __name__ == '__main__':

    req = requestHandler()
    res = req.send('POST',Configure.host + '/futureloan/member/register',
                   json={"mobile_phone":"13413766441","pwd":"123456"},
                   headers = {"X-lemonban-Media-Type":"lemonban.v2"}
                   )
    print(res)